import 'package:flutter/material.dart';
import 'HomeWidget.dart';
import 'ZhongcaoMao.dart';
import 'HuodongZhongxin.dart';
import 'ShoppingCart.dart';
import 'Member.dart';
//import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
class MainWidget extends StatefulWidget {
  int currentPage=0;
  @override
  State<MainWidget> createState() => _MainWidgetState();
}

class _MainWidgetState extends State<MainWidget> {

  var _pageController = new PageController(initialPage: 0);

  @override
  void initState() {
    super.initState();

  }

  @override
  Widget build(BuildContext context) {

    List<Widget> list = List();
    list.add(HomeWidget());
    list.add(ZhongcaoMao());
    list.add(HuodongZhongxin());
   // list.add(ShoppingCart());
    list.add(Member());
    return WillPopScope(child: Scaffold(
      body: PageView.builder(
        controller: _pageController,
        physics: NeverScrollableScrollPhysics(),
        itemBuilder: (c,int b){
          if(widget.currentPage==0){
            return new HomeWidget();
          }
          if(widget.currentPage==1){
            return new ZhongcaoMao();
          }
          if (widget.currentPage==2){
            return new HuodongZhongxin();
          }
          if (widget.currentPage==3){
           // return new ShoppingCart();
          }
          if(widget.currentPage==4){
              return new Member();

          }
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        elevation: 0.0,
        items: [
          BottomNavigationBarItem(icon: Image.asset("images/homenot.png"),
              activeIcon: Image.asset("images/homeselect.png"),
              title:Text("精选",style: TextStyle(color: widget.currentPage==0?Color(0xffd81e06):Color(0xffeeeeee)),) ),
          BottomNavigationBarItem(icon: Image.asset("images/haicao.png"),
              activeIcon: Image.asset("images/haicaoselect.png"),
              title:Text("种草猫",style: TextStyle(color: getTextColor(1)),) ),
          BottomNavigationBarItem(icon: Image.asset("images/huodong.png"),
              activeIcon: Image.asset("images/huodongselect.png"),
              title:Text("活动中心",style: TextStyle(color: getTextColor(2)),) ),
          BottomNavigationBarItem(icon: Image.asset("images/gouwuche.png"),
              activeIcon: Image.asset("images/gouwucheselect.png"),
              title:Text("购物车",style: TextStyle(color: getTextColor(3)),) ),
          BottomNavigationBarItem(icon: Image.asset("images/people.png"),
              activeIcon: Image.asset("images/peopleselect.png"),
              title:Text("我的",style: TextStyle(color: getTextColor(4)),) ),
        ]
        ,
        type: BottomNavigationBarType.fixed,
        currentIndex: widget.currentPage,
        onTap: (i){

          setState(() {
            widget.currentPage=i;
          });
        },

      ),
      bottomSheet: Container(color: Colors.grey,height: 1.0,),
    ), onWillPop: (){
      SystemChannels.platform.invokeMethod('SystemNavigator.pop');
    });

  }

  Color getTextColor(int index){
    if(widget.currentPage==index){
      return Color(0xffd81e06);
    }else {
     return Color(0xffeeeeee);
    }
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

}